package com.bjwl.service.impl;

import com.bjwl.dao.InvoiceMapper;
import com.bjwl.pojo.Invoice;
import com.bjwl.pojo.vo.QueryInvoiceVo;
import com.bjwl.service.InvoiceService;
import com.bjwl.utils.Log4jUtils;
import com.bjwl.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: dzx
 * @Date:Create：in 2020/5/13 8:55
 * @Description:
 * @Modified By：
 * @Version: 1.0
 */
@Service
public class InvoiceServiceImpl implements InvoiceService {

    @Autowired
    private InvoiceMapper invoiceMapper;

    @Override
    public PageBean<Invoice> findAllInvoice(QueryInvoiceVo vo) {
        PageBean<Invoice> pageBean = new PageBean<Invoice>(vo.getPageNum(), 10, invoiceMapper.getInvoiceTotalRecord(vo));
        pageBean.setData(invoiceMapper.getInvoiceList(pageBean, vo));
        return pageBean;
    }

    @Override
    public boolean addInvoice(Invoice vo) {
        try {
            invoiceMapper.addInvoice(vo);
            return true;
        } catch (Exception e) {
            Log4jUtils.LITERAL3.getLog().error(e.getMessage());
            return false;
        }
    }

    @Override
    public Invoice editS(Integer id) {
        return invoiceMapper.findInvoiceById(id);
    }

    @Override
    public boolean updateInvoice(Invoice invoice) {
        try {
            invoiceMapper.updateInvoice(invoice);
            return true;
        } catch (Exception e) {
            Log4jUtils.LITERAL3.getLog().error(e.getMessage());
            return false;
        }
    }

    @Override
    public boolean deleteInvoice(Integer id) {
        try {
            invoiceMapper.deleteInvoice(id);
            return true;
        } catch (Exception e) {
            Log4jUtils.LITERAL3.getLog().error(e.getMessage());
            return false;
        }
    }
}
